<template>
  <div class="mint-search">
    <div class="mint-searchbar" :class="!(currentType==='type2')?'black':''">
      <div class="mint-searchbar-inner" v-model="currentType">
        <i class="mintui mintui-search"></i>
        <input ref="input" type="search" v-model="currentValue" :placeholder="placeholder" class="mint-searchbar-core">
      </div>
      <a class="mint-searchbar-cancel" v-if="!(currentType==='type2')" v-text="cancelText" @click="goHome"></a>
    </div>
    <div class="mint-search-list" v-show="show || currentValue">
      <div class="mint-search-list-warp">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'mint-search',
    data () {
      return {
        visible: false,
        currentValue: this.value,
        currentType: this.type
      }
    },
    watch: {
      currentValue (val) {
        this.$emit('input', val)
      },
      value (val) {
        this.currentValue = val
      },
      type () {
        console.log(arguments)
      }
    },
    props: {
      value: String,
      type: String,
      autofocus: Boolean,
      show: Boolean,
      cancelText: {
        default: '取消'
      },
      placeholder: {
        default: '搜索'
      },
      result: Array
    },
    methods: {
      goHome () {
        // this.$router.push({path: '/'})
        history.back()
      }
    },
    mounted () {
      this.autofocus && this.$refs.input.focus()
    }
  }
</script>

<style lang="scss">
  .mint-searchbar {
    z-index: 3;
  }

  .mint-search-list {
    padding-top: 52px;
    /*background: rgba(0,0,0,.5);*/
    overflow-scrolling: touch;
    -webkit-overflow-scrolling: touch;
    z-index: 2;
  }

  .mint-searchbar {
    background: #f2f2f2;
    .mint-searchbar-inner {
      .mint-searchbar-core {
        text-indent: 0.16rem;
      }
    }
  }

  .black.mint-searchbar {
    background: #0f1316;
    .mint-searchbar-cancel {
      color: #ffffff;
    }
  }
</style>
